<template>
  <div class="license" style="display: flex;height: 100%;justify-content: center;align-items: center">
    <el-upload
      ref="upload"
      style="width: 400px"
      :limit="1"
      accept=".lic"
      :action="url"
      :disabled="isUploading"
      :on-progress="handleFileUploadProgress"
      :on-success="handleFileSuccess"
      drag
    >
      <i class="el-icon-upload" />
      <div class="el-upload__text">
        {{ $t('将文件拖到此处，或') }}
        <em>{{ $t('上传') }}</em>
      </div>
      <div slot="tip" class="el-upload__tip" style="color:red;text-align: center;margin-top: 15px;"> {{ $t('提示:仅允许导入“.lic”格式文件！') }}</div>
    </el-upload>
  </div>
</template>

<script>
export default {
  name: 'UploadLicense',
  data() {
    return {
      // 上传的地址
      url: process.env.VUE_APP_BASE_API + '/license/upload',
      isUploading: false
    }
  },
  methods: {
    handleFileUploadProgress() {
      this.isUploading = true
    },
    // 文件上传成功处理
    handleFileSuccess(response) {
      this.isUploading = false
      this.$refs.upload.clearFiles()
      this.$alert(response.msg, this.$t('授权结果'), { dangerouslyUseHTMLString: true })
      setTimeout(() => {
        window.location.href = '/'
      }, 5000)
    }
  }
}
</script>

<style scoped>

</style>
